package com.dearbinge.opentapi.content.version;

import com.dearbinge.data.api.version.VersionService;
import com.dearbinge.data.pojo.version.Version;
import com.dearbinge.utils.ResultMsg;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * app版本控制层
 *
 * @author cl
 * @date 2019/1/10
 */
@Api(description = "app版本")
@RestController
@RequestMapping("/version")
@CrossOrigin
public class VersionController extends WebMvcConfigurerAdapter {
    @Autowired
    private VersionService versionService;

    /**
     * 新增app最新版本
     */
    @ApiOperation(value = "新增app最新版本",notes = "新增app最新版本(type = 1 ios , 2 安卓")
    @RequestMapping(value = "/insertOrUpdateCart", method = RequestMethod.POST)
    public ResultMsg<String> insertAppVersion(@RequestBody Version version) {
        try {
            Integer dataCode ;
                dataCode = versionService.insertAppVersion(version);
                if (dataCode >0){
                    return ResultMsg.ok("增加成功");
                }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultMsg.error(500,"系统异常");
    }

    /**
     * 查询app最新版本
     */
    @ApiOperation(value = "查询app最新版本",notes = "查询app最新版本(type = 1 ios , 2 安卓")
    @ApiImplicitParam(name = "type", value = "类型 1 ios , 2 安卓", paramType = "query")
    @RequestMapping(value = "/getAppVersion",method = RequestMethod.GET)
    public ResultMsg<Version> getCollectById(Integer type) {
        try {
            Version version = versionService.getAppVersion(type);
            return ResultMsg.ok(version);

        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultMsg.error(500,"系统异常");
    }
}
